﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using STAR.Spring.Framework.Module;
using System.Web.UI;
using System.Data;
using ITSupportPlatform.DAL;

namespace ITSupportPlatform.Handler
{
    public class GroupFinishTaskSearchHander : CustomResponse
    {
        object[] requestParams;

        public override System.Data.DataTable ReadData(string requestName, params object[] parms)
        {
            requestParams = parms;
            return base.ReadData("ITsupport_GetGroupFinishedData");
        }

        public override dynamic CreateResult(DataTable dt)
        {
            List<dynamic> resultItems = base.CreateResult(dt);
            if (requestParams == null || requestParams.Length != 5)
            {
                return null;
            }

            string fromDay = requestParams[0].ToString();
            string toDay = requestParams[1].ToString();
            string person = requestParams[2].ToString();
            string systemValue = requestParams[3].ToString();
            string probValue = requestParams[4].ToString();

            List<dynamic> resultInfos = base.CreateResult(dt);
            if (!string.IsNullOrEmpty(fromDay))
            {
                DateTime fromDayDateTime = DateTime.Parse(fromDay);
                resultInfos = resultInfos.Where(x => DateTime.Parse(x.StartTime) >= fromDayDateTime).ToList();
            }
            if (!string.IsNullOrEmpty(toDay))
            {
                DateTime DayDateTime = DateTime.Parse(toDay);
                resultInfos = resultInfos.Where(x => DateTime.Parse(x.StartTime) <= DayDateTime).ToList();
            }
            if (!string.IsNullOrEmpty(person)&&person!=Guid.Empty.ToString())
            {
                //Guid uid = Guid.Parse(person);
                resultInfos = resultInfos.Where(x => x.PartID == person).ToList();
            }
            if (!string.IsNullOrEmpty(systemValue))
            {
                resultInfos = resultInfos.Where(x => x.svalue == systemValue).ToList();
            }
            if (!string.IsNullOrEmpty(probValue))
            {
                resultInfos = resultInfos.Where(x => x.pvalue == probValue).ToList();
            }
            return resultInfos;
        }

        DAL.FounderOAResourceGroupEntities context = new DAL.FounderOAResourceGroupEntities();

        public List<Org_Users> GetInfomationUserList()
        {
            Guid depId = new Guid(System.Configuration.ConfigurationManager.AppSettings["InfomationDept"]);
            List<DAL.Org_Users> userInfos = context.Org_Users.Where(x => x.DeptID.Value == depId).OrderBy(x => x.Name).ToList();
            userInfos.Insert(0, new DAL.Org_Users()
            {
                ID = Guid.Empty,
                Name = "--请选择--"
            });
            return userInfos;
        }
        public List<ITSupportType> GetSystemTypes()
        {
            List<ITSupportType> systemTypes = context.ITSupportType.Where(x => x.SuperclassValue == "0").ToList();
            systemTypes.Insert(0, new ITSupportType()
            {
                ProblemClassifyName = "--请选择--",
                ProblemClassifyValue = ""
            });
            return systemTypes;
        }
    }
}